﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Plataforma10Demo.Models;

namespace Plataforma10Demo.Controllers
{
    public class ServiciosController : Controller
    {
        //
        // GET: #!/Servicios/

        public ActionResult Pasajes()
        {
            return PartialView("Pasajes");
        }



        public ActionResult Butacas()
        {
            return PartialView("Butacas");
        }

        public ActionResult BuscarServicio()
        {
            var ObjResult = new Result();
            var servicioList = new List<Servicios>();

            var calidades = new[] { "Comun", "Semi Cama", "Cama", "Ejecutivo", "Internacional", "Pu", "Suite", "Común Con Aire" };
            var empresas = new[] { "El rapido", "Urquiza", "Cruz del Sur", "Espreso Brazilia", "Milonga Bus", "Rosario express" };


            var rnd = new Random();
            var interaciones = rnd.Next(1, 40);

            for (var i = 0; i < 10; i++)
            {
                servicioList.Add(new Servicios
                {
                    Butacas = rnd.Next(1, 50),
                    Calidad = calidades[rnd.Next(0, 3)],
                    EsInternacional = false,
                    IdProveedor = rnd.Next(0, 100),
                    IdProveedorTransportista = 133,
                    NombreProveedorTransportista = empresas[rnd.Next(0, 5)],
                    Precio = rnd.Next(40, 1000),
                    IndiceServicio = i,
                    ClaveSolicitud = "SR" + rnd.Next(1, 100000)
                });
            }

            ObjResult.success = true;
            ObjResult.data = servicioList;
            ObjResult.results = servicioList.Count;
            ObjResult.message = "Ok";

            return Json(ObjResult, JsonRequestBehavior.AllowGet);

        }

        public ActionResult BuscarButacas()
        {
            var ObjResult = new Result();
            var itemsList = new List<Butacas>();

            for (var i = 0; i < 30; i++)
            {
                itemsList.Add(new Butacas
                                  {
                                      NumeroButaca = i,
                                      IsOcupado = GetRandomBoolean(),
                                      IsPrimerPiso = (i > 14) ? true : false,
                                      IsEdited = false
                                  });
            }
       

            ObjResult.success = true;
            ObjResult.data = itemsList;
            ObjResult.results = itemsList.Count;
            ObjResult.message = "Ok";

            return Json(ObjResult, JsonRequestBehavior.AllowGet);

        }


        public static bool GetRandomBoolean()
        {
            return new Random().Next(100) % 2 == 0;
        }

    }

}

